package com.zyk.leetcode;

/**
 *
 * https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/
 *
 * @author zhangsan
 * @date 2021/3/24 11:32
 */
public class C1217 {

    // 暴力解
    public static int minCostToMoveChips(int[] position) {
        int r = 0;
        for (int i = 0; i < position.length; i++) {
            r += process(position, i, 0);
        }
        return r;
    }

    // 所有都移到最后一个的代价
    public static int process(int[] position, int i, int cost) {
        if(i >= position.length-1) {
            return i==position.length-1? cost: Integer.MAX_VALUE;
        }
        int r1 = process(position, i+1, cost+1);
        int r2 = process(position, i+2, cost);
        return Math.min(r1, r2);
    }

    public static void main(String[] args) {
        int [] chips = {1,2,2,2,2};
        int r1 = minCostToMoveChips(chips);
        System.out.println(r1);
    }

}
